#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "queue.h"
#include "common.h"


void initQueue(ArrayQueue *q) {
    q->front = 0;
    q->rear = -1;
    q->size = 0;
}

bool isFull(ArrayQueue *q) {
    return q->size == QUEUE_SIZE;
}

bool isEmpty(ArrayQueue *q) {
    return q->size == 0;
}

bool enqueue(ArrayQueue *q, Request value) {
    if (isFull(q)) return false;
    
    q->rear = (q->rear + 1) % QUEUE_SIZE;
    q->data[q->rear] = value;
    q->size++;
    return true;
}

bool dequeue(ArrayQueue *q, Request *value) {
    if (isEmpty(q)) return false;
    
    *value = q->data[q->front];
    q->front = (q->front + 1) % QUEUE_SIZE;
    q->size--;
    return true;
}

Request peek(ArrayQueue *q) {
    if (isEmpty(q))
    {
        Request cmd = {NIL};
        return cmd;
    }
    return q->data[q->front];
}
